package com.open4cn.simulator.connect.tcp.handler;

import com.open4cn.simulator.core.device.DeviceStatus;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description 阻断消息输入
 * @Email yinxiaopeng@zj.tech
 * @date 2022-05-03 15:01
 */
@ChannelHandler.Sharable
public class ReadBlockHandler extends ChannelInboundHandlerAdapter {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private DeviceStatus deviceStatus;

    public ReadBlockHandler(DeviceStatus deviceStatus) {
        this.deviceStatus = deviceStatus;
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        boolean suspended = null != deviceStatus ? deviceStatus.isSuspended() : false;
        if (suspended) {
            logger.info("设备处于暂停中!");
            return;
        }
        super.channelRead(ctx, msg);
    }
}
